<template>
  <view class="container">
    <view class="menu-container">
      <view class="menu-list">
        <u-cell-group>
          <u-cell-item @click="gotoPath('/pages/setting/safe/index',false)" title="安全中心" icon="lock">
          </u-cell-item>
          <u-cell-item @click="gotoPath('/pages/setting/feedback',true)" title="反馈&建议"
                       icon="volume"></u-cell-item>

          <u-cell-item @click="gotoPath('/pages/setting/xieyi',false)" title="协议与隐私政策"
                       icon="order"></u-cell-item>
          <u-cell-item @click="gotoPath('/pages/setting/beian',false)" title="应用备案号" icon="bookmark">
            查看备案信息
          </u-cell-item>
          <u-cell-item title="营业执照" icon="photo"  @click="gotoPath('/pages/packageA/h5/article?key=license&title=营业执照',false)">
            查看营业执照
					</u-cell-item>

          <u-cell-item @click="check_update()" title="当前版本" icon="reload">
            <text>{{ app_version }}</text>
            <u-badge v-if="show_version" count="有新版本" :absolute="false" slot="right-icon"></u-badge>

          </u-cell-item>


          <u-cell-item v-if="hasLogin" @click="logout()" title="退出登录" icon="close-circle">
          </u-cell-item>
        </u-cell-group>
        <view class="footer">
          <view >{{ copyright}}</view>
        </view>
      </view>
    </view>



  </view>
</template>

<script>
// #ifdef APP-PLUS || MP-WEIXIN
import checkappupdate from 'js_sdk/wonyes-checkappupdate/wonyes/checkappupdate.js'
// #endif
import constConfig from '@/const.js'
import api from "@/common/base_api";
export default {
  components: {},
  data() {
    return {
      beian_no: constConfig.beian_no,
      app_version: null,
      show_version: false,
      copyright: '',
    }
  },
  computed: {
    userInfo() {
      return this.$store.getters.user
    },
    unreadCount() {
      return this.$store.getters.unread_count || 0
    }

  },
  methods: {

    base_info(){
      api.baseInfo().then(res=>{
        if (res.code==0){
          this.beian_no = res.data.beian_no;
          this.beian_no_xcx = res.data.beian_no_xcx;
          this.beian_url = res.data.beian_url
          this.copyright = res.data.copyright;
        }
      })
    },
    //获取系统版本信息
    getSystemInfo() {
      let info = uni.getSystemInfoSync();
      console.log(info)

      this.app_version = info.appVersion;
      // #ifdef APP-PLUS
      this.check_app(info);
      // #endif
    },

    check_app(info) {
      let that = this
      this.$u.api.checkAppVersion({
        platform: info.platform,
        appWgtVersion: info.appWgtVersion || info.appVersion,
        version: this.app_version
      }).then(res => {
        if (res.code == 0) {
          that.show_version = true;
        }
      })
    },


    check_update() {
      if (uni.getSystemInfoSync().platform == 'h5') {
        this.$u.toast('请在APP端更新')
        return
      }
      // #ifdef MP-WEIXIN
      checkappupdate.wx_check_update()
      // #endif

      // #ifdef APP-PLUS
      checkappupdate.check({
        title: "检测到有新版本！",
        content: "请升级app到最新版本！",
        canceltext: "暂不升级",
        oktext: "立即升级",
        api: constConfig.baseUrl + '/update',
        barbackground: "rgba(50,50,50,0.8)", //进度条背景色，默认灰色，可自定义rgba形式色值
        barbackgroundactive: "rgba(32,165,58,1)" //进度条前景色色，默认绿色，可自定义rgba形式色值
      })
      // #endif


    },


    logout() {
      uni.showModal({
        title: '',
        content: '确定退出登录？',
        success: (res) => {
          if (res.confirm) {
            this.$store.dispatch('logout')
            uni.reLaunch({
              url: '/pages/login/index'
            })
          }
        }
      })
    },
    categorySet() {
      uni.navigateTo({
        url: "/pages/setting/category"
      })
    }
  },
  onLoad(options) {
    this.base_info();
    this.getSystemInfo()
    // #ifdef MP-WEIXIN
    this.beian_no = constConfig.beian_no_xcx;
    // #endif
  },
  onShow() {
    if (this.hasLogin) {
      this.$store.dispatch('getUserInfo')
    }
  }
}
</script>

<style lang="scss">
.container {
  background-color: #f5f5f5;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}

%flex-center {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

%section {
  display: flex;
  justify-content: space-around;
  align-content: center;
  background: #fff;
  border-radius: 10upx;
}


.menu-list {
  margin-top: 30upx;
  background: #fff;
  border-radius: 10upx;

  switch {
    transform: scale(0.7, 0.7)
  }
}

.list-item {
  width: 100%;
  padding: 0rpx;
  background-color: #FFFFFF !important;
  border: initial;
  text-align: initial;
}

.list-item::after {
  border: initial;
}
.footer{
  padding: 20rpx;
  position: fixed;
  bottom: 0;
}
</style>
